﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Dowload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strRequest = Request.QueryString["filename"];
        //-- if something was passed to the file querystring
        //get absolute path of the file
        if (!string.IsNullOrEmpty(strRequest))
        {
            string path = Server.MapPath("~\\Admin\\images\\Items\\");
            //get file object as FileInfo
            System.IO.FileInfo file = new System.IO.FileInfo(path + strRequest);
            //-- if the file exists on the server
            //set appropriate headers
            if (file.Exists)
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
                //if file does not exist
            }
            else
            {
                Response.Write("This file does not exist.");
            }
            //nothing in the URL as HTTP GET
        }
        else
        {
            Response.Write("Please provide a file to download.");
        }
    }
}
